package com.hongdee.market.grievance.controller;

import com.hongdee.common.util.TokenUtil;
import com.hongdee.market.grievance.service.ITMarketWhineService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by Liu XiaoLong
 * Date: 2017/11/1.
 * Remark:
 */
@RestController
@RequestMapping("/market/grievance")
public class TMarketWhineController {
    @Autowired
    private ITMarketWhineService itMarketWhineService;

    /**
     * @Name: 分页查询
     * @Author: Liu XiaoLong
     * @Date: 2017/11/1 10:37
     * @Remark:
     */
    @RequestMapping("/page")
    public Map page(@RequestParam(name = "uid", defaultValue = "") String uid,
                    @RequestParam(name = "token", defaultValue = "") String token,
                    @RequestParam(name = "page", defaultValue = "0") int page,
                    @RequestParam(name = "limit", defaultValue = "10") int limit,
                    @RequestBody Map queryData) throws Exception {

        Map map = itMarketWhineService.page(uid,queryData,page,limit);
        map.put("success", true);
        map.put("msg", "查询成功");
        return map;
    }

    /**
     * @Name: 判断是否是客服经理
     * @Author: Liu XiaoLong
     * @Date: 2017/11/1 10:38
     * @Remark:
     */
    @RequestMapping("/isKF")
    public Map isKF(@RequestParam(name = "uid", defaultValue = "") String uid,
                    @RequestParam(name = "token", defaultValue = "") String token,
                    @RequestParam(name = "id", defaultValue = "") String id,
                    @RequestParam(name = "node", defaultValue = "") String node) throws Exception {

        Map map = itMarketWhineService.isKFOrNot(uid,id,node);
        map.put("success", true);
        map.put("msg", "查询成功");
        return map;
    }

    /**
     * @Name: 抱怨审批
     * @Author: Liu XiaoLong
     * @Date: 2017/11/1 10:46
     * @Remark:
     */
    @RequestMapping("/approve")
    public Map approve(@RequestParam(name = "uid", defaultValue = "") String uid,
                    @RequestParam(name = "token", defaultValue = "") String token,
                    @RequestParam(name = "id", defaultValue = "") String id,
                    @RequestParam(name = "nodes", defaultValue = "") String nodes,
                    @RequestParam(name = "nextNode", defaultValue = "") String nextNode,
                    @RequestParam(name = "remark", defaultValue = "") String remark) throws Exception {

        Map map = itMarketWhineService.submitApprove(uid,id,nodes,nextNode,remark);
        map.put("success", true);
        map.put("msg", "提交成功");
        return map;
    }

/**
 * @Name: 详情查询
 * @Author: Liu XiaoLong
 * @Date: 2017/11/1 10:48
 * @Remark:
 */
    @RequestMapping("/info")
    public Map info(@RequestParam(name = "uid", defaultValue = "") String uid,
                    @RequestParam(name = "token", defaultValue = "") String token,
                    @RequestParam(name = "id", defaultValue = "") String id) throws Exception {

        Map map = itMarketWhineService.info(uid,id);
        map.put("success", true);
        map.put("msg", "查询成功");
        return map;
    }

    /**
     * @Name: 抱怨类型修改
     * @Author: Liu XiaoLong
     * @Date: 2017/11/1 10:50
     * @Remark:
     */
    @RequestMapping("/Degree")
    public Map Degree(@RequestParam(name = "uid", defaultValue = "") String uid,
                    @RequestParam(name = "token", defaultValue = "") String token,
                    @RequestParam(name = "id", defaultValue = "") String id,
                    @RequestParam(name = "degree", defaultValue = "") String degree,
                    @RequestParam(name = "type", defaultValue = "") String type) throws Exception {

        Map map = itMarketWhineService.typeAdjust(uid,id,type,degree);
        map.put("success", true);
        map.put("msg", "调整成功");
        return map;
    }

    /**
     * @Name: 完成
     * @Author: Liu XiaoLong
     * @Date: 2017/11/1 10:51
     * @Remark:
     */
    @RequestMapping("/complete")
    public Map complete(@RequestParam(name = "uid", defaultValue = "") String uid,
                      @RequestParam(name = "token", defaultValue = "") String token,
                      @RequestParam(name = "id", defaultValue = "") String id,
                      @RequestParam(name = "status", defaultValue = "") String status,
                      @RequestParam(name = "remark", defaultValue = "") String remark) throws Exception {

        Map map = itMarketWhineService.completeApprove(uid,id,status,remark);
        map.put("success", true);
        map.put("msg", "任务已完成");
        return map;
    }

    /**
     * @Name: 获取当前角色
     * @Author: Liu XiaoLong
     * @Date: 2017/11/1 10:52
     * @Remark:
     */
    @RequestMapping("/role")
    public Map role(@RequestParam(name = "uid", defaultValue = "") String uid,
                        @RequestParam(name = "token", defaultValue = "") String token) throws Exception {

        Map map = itMarketWhineService.role(uid);
        map.put("success", true);
        map.put("msg", "查询成功");
        return map;
    }

}
